package com.cloud.easy.im.handler.strategy;

import com.cloud.easy.im.argeement.Agreement;
import com.cloud.easy.im.event.ServerEventListener;
import io.netty.channel.Channel;

/**
 * 协议类型策略角色
 *
 * @author wangjian
 * @version 0.1.0
 * @create 2020年09月03日5:17 下午
 */
public abstract class AgreementStrategy {

    private final byte myType;

    public AgreementStrategy(byte myType) {
        this.myType = myType;
    }

    public byte getMyType() {
        return myType;
    }

    /**
     * 策略选择实现
     *
     * @param type 策略类型
     * @return
     */
    public boolean algorithmInterface(byte type) {
        return type == this.getMyType();
    }

    /**
     * 针对数据的处理逻辑
     *
     * @param session
     * @param dataFromClient
     * @param serverEventListener
     */
    public abstract void handler(final Channel session, final Agreement dataFromClient, ServerEventListener serverEventListener) throws Exception;

}
